import time

from selenium.webdriver.support.ui import WebDriverWait
class Base():
    def __init__(self,driver):
        self.driver=driver

    def open_url(self,url):
        self.driver.get(url)

    def quit(self):
        self.driver.quit()

    def find_element(self,loc):
        try:
            WebDriverWait(self.driver,20,0.5).until(lambda driver:driver.find_element(*loc).is_displayed())
            return self.driver.find_element(*loc)
        except Exception as e:
            str=time.strftime("%Y%m%d-%H%M%S")
            self.driver.save_screenshot(str+'.png')
            print(e)

        # 点击事件

    def click(self, loc):
        self.find_element(loc).click()
        # 输入事件

    def send_keys(self, loc, info):
        self.find_element(loc).send_keys(info)
        # 清空事件

    def clear(self, loc):
        self.find_element(loc).clear()
        # 文本事件

    def text(self, loc):
        return self.find_element(loc).text
        # 进入frame框架

    def frame(self, loc):
        self.driver.switch_to.frame(self.find_element(loc))
        # 退出frame框架

    def frame_quit(self):
        self.driver.switch_to.default_content()
